﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010.Views.MetroUI;
using DevExpress.XtraEditors;
using Sunboxsoft.WinForm.Shell.Common;

namespace Sunboxsoft.WinForm.Shell
{
    public partial class SwitchModuleForm : Form
    {
        public IModule SelectedModule { get; private set; }

        public SwitchModuleForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            for (int index = 0; index < RuntimeData.Instance.ModuleInstanceArray.Length; index++)
            {
                TileItemElement element = new TileItemElement();
                element.Text = RuntimeData.Instance.ModuleInstanceArray[index].Name;
                TileItem tileItem = new TileItem();
                tileItem.Elements.Add(element);
                tileItem.Id = index;
                tileItem.Name = "tileItem" + index.ToString();
                tileItem.Tag = RuntimeData.Instance.ModuleInstanceArray[index];
                this.tileGroup2.Items.Add(tileItem);
            }
        }

        private void ctlTileControl_ItemClick(object sender, TileItemEventArgs e)
        {
            IModule module = e.Item.Tag as IModule;
            if (module != null)
            {
                SelectedModule = module;
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
